from django.db import models


class Permission(models.Model):
	'''权限表'''
	url = models.CharField(verbose_name='权限URL', max_length=64)
	title = models.CharField(verbose_name='权限信息', max_length=32)

	def __str__(self):
		return self.title


class Role(models.Model):
	'''角色表'''
	name = models.CharField(verbose_name='角色名称', max_length=32)
	permissions = models.ManyToManyField(to=Permission, verbose_name='角色所拥有的权限', blank=True)

	def __str__(self):
		return self.name


class User(models.Model):
	'''用户表'''
	username = models.CharField(verbose_name='用户名', max_length=32)
	password = models.CharField(verbose_name='密码', max_length=32)
	gender = models.IntegerField(verbose_name='性别', choices=[(0, '男'), (1, '女')], default=0)
	age = models.IntegerField(verbose_name='年龄', default=0)
	email = models.EmailField(verbose_name='邮箱', null=True, blank=True)
	phone = models.CharField(verbose_name='电话', max_length=20, null=True, blank=True)
	createDateTime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
	roles = models.ManyToManyField(to=Role, verbose_name='用户所拥有是角色', blank=True)

	def __str__(self):
		return self.username
